/**
 * 员工工资条信息
 */

/**
 * 表单自定义控制器
 */
app.controller('formSelfCtrl', ['$scope', '$http', FormSelfController]);
function FormSelfController($scope, $http){
	//考勤绩效取反
	//$scope.valueMap['attendancePerformance'] = 0-parseFloat($scope.valueMap['attendancePerformance']);

	$scope.changeValueMap = function(field) {
		console.log('------field-----', field);
		if(field == 'basicSalary' || field == 'positionSalary' || field == 'performanceSalary'
			|| field == 'transSubsidy' || field == 'cateringSubsidy' || field == 'jobPromotion'
			|| field == 'quarterBonus' || field == 'yearEndBonus' || field == 'attendancePerformance'
			|| field == 'otherPerformance' || field == 'otherCost' || field == 'wagesPay'
			|| field == 'retirementPersonal' || field == 'loseWorkPersonal' || field == 'healthPersonal'
			|| field == 'accumulationFundPersonal'){

			//其他绩效
			//应发工资 = 基本底薪+岗位薪资+绩效薪资+交通补贴+餐饮补贴+岗位提奖+季度提奖+年终奖-考勤绩效+其他绩效
			var basicSalary = parseFloat($scope.valueMap["basicSalary"]); // 基本底薪
			var positionSalary = parseFloat($scope.valueMap["positionSalary"]); // 岗位薪资
			var performanceSalary = parseFloat($scope.valueMap["performanceSalary"]); // 绩效薪资
			var transSubsidy = parseFloat($scope.valueMap["transSubsidy"]); // 交通补贴
			var cateringSubsidy = parseFloat($scope.valueMap["cateringSubsidy"]); // 餐饮补贴
			var jobPromotion = parseFloat($scope.valueMap["jobPromotion"]); // 岗位提奖
			var quarterBonus = parseFloat($scope.valueMap["quarterBonus"]); // 季度提奖
			var yearEndBonus = parseFloat($scope.valueMap["yearEndBonus"]); // 年终奖
			var attendancePerformance = 0-parseFloat($scope.valueMap["attendancePerformance"]); // 考勤绩效
			var otherPerformance = parseFloat($scope.valueMap["otherPerformance"]); // 其他绩效
			var otherCost = parseFloat($scope.valueMap["otherCost"]); // 其他费用

			if((basicSalary || basicSalary==0) && (positionSalary || positionSalary==0) && (performanceSalary || performanceSalary==0)
				&& (transSubsidy|| transSubsidy==0) && (cateringSubsidy || cateringSubsidy==0)
				&& (jobPromotion || jobPromotion==0) && (quarterBonus || quarterBonus==0) && (yearEndBonus || yearEndBonus==0)
				&& (attendancePerformance || attendancePerformance==0)){
				var count = basicSalary+positionSalary+performanceSalary+transSubsidy+cateringSubsidy+jobPromotion
					+quarterBonus+yearEndBonus-attendancePerformance;
				$scope.valueMap["wagesPay"] = count.toFixed(2);
				//个税收入=应发工资+其他费用
				$scope.valueMap["taxPaySlip"] = count.toFixed(2);
				if((otherCost || otherCost==0)){
					//个税收入=应发工资+其他费用
					$scope.valueMap["taxPaySlip"] = (count+otherCost).toFixed(2);
				}
			}
			if((basicSalary || basicSalary==0) && (positionSalary || positionSalary==0) && (performanceSalary || performanceSalary==0)
				&& (transSubsidy|| transSubsidy==0) && (cateringSubsidy || cateringSubsidy==0)
				&& (jobPromotion || jobPromotion==0) && (quarterBonus || quarterBonus==0) && (yearEndBonus || yearEndBonus==0)
				&& (attendancePerformance || attendancePerformance==0) && (otherPerformance|| otherPerformance==0)){
				var count = basicSalary+positionSalary+performanceSalary+transSubsidy+cateringSubsidy+jobPromotion
					+quarterBonus+yearEndBonus-attendancePerformance+otherPerformance;
				$scope.valueMap["wagesPay"] = count.toFixed(2);

				//个税收入=应发工资+其他费用
				$scope.valueMap["taxPaySlip"] = count.toFixed(2);
				if((otherCost || otherCost==0)){
					//个税收入=应发工资+其他费用
					$scope.valueMap["taxPaySlip"] = (count+otherCost).toFixed(2);
				}
			}


			//其他费用
			//应付工资 = 应发工资-养老保险（个人）-失业保险（个人）-医疗保险（个人）-公积金（个人）+其他费用
			var wagesPay = parseFloat($scope.valueMap["wagesPay"]); // 应发工资
			var retirementPersonal = parseFloat($scope.valueMap["retirementPersonal"]); // 养老保险（个人）
			var loseWorkPersonal = parseFloat($scope.valueMap["loseWorkPersonal"]); // 失业保险（个人）
			var healthPersonal = parseFloat($scope.valueMap["healthPersonal"]); // 医疗保险（个人）
			var accumulationFundPersonal = parseFloat($scope.valueMap["accumulationFundPersonal"]); // 公积金（个人）

			if((wagesPay || wagesPay==0) && (retirementPersonal || retirementPersonal==0) && (loseWorkPersonal || loseWorkPersonal==0)
				&& (healthPersonal || healthPersonal==0) && (accumulationFundPersonal || accumulationFundPersonal==0)){
				var count = wagesPay-retirementPersonal-loseWorkPersonal-healthPersonal-accumulationFundPersonal;
				$scope.valueMap["needPaySlip"] = count.toFixed(2);
			}
			if((wagesPay || wagesPay==0) && (retirementPersonal || retirementPersonal==0) && (loseWorkPersonal || loseWorkPersonal==0)
				&& (healthPersonal || healthPersonal==0) && (accumulationFundPersonal || accumulationFundPersonal==0) && (otherCost || otherCost==0)){
				var count = wagesPay-retirementPersonal-loseWorkPersonal-healthPersonal-accumulationFundPersonal+otherCost;
				$scope.valueMap["needPaySlip"] = count.toFixed(2);
			}

		}
	}
}


